#!/usr/bin/env python
# encoding: utf-8
"""
#-------------------------------------------------------------------#
#                   CONFIDENTIAL --- CUSTOM STUDIOS                 #     
#-------------------------------------------------------------------#
#                                                                   #
#                   @Project Name : Globallawonline                #
#                                                                   #
#                   @File Name    : SqldataDeduplication.py                      #
#                                                                   #
#                   @Programmer   : 李建                            #
#                                                                   #  
#                   @Start Date   : 2021/1/15 16:00                 #
#                                                                   #
#                   @Last Update  : 2021/1/15 16:00                 #
#                                                                   #
#-------------------------------------------------------------------#
# Classes:该类用于进行Sql数据的去重                                                          #
#                                                                   #
#-------------------------------------------------------------------#
"""
import datetime
import threading

from DBCountrol.MySQLHelper import Mysqlhelper
from DataDeduplication.settings import SqllawdatadeduplestatementS, SqlcasedatadeduplestatementS


class SqldataDuplication:
    def lawdataduple(self):
        print("sql法律数据去重任务启动")
        for sql in SqllawdatadeduplestatementS:
            try:
                result = Mysqlhelper().delete(sql)
            except Exception as e:
                with open("sqlerro.txt", "a+", encoding="utf-8") as f:
                    f.write(str(datetime.datetime.now()) + ":" + "sql语句执行出错：" + sql + '\n')
                print(e)
        print("sql法律数据去重任务结束")

    def casedataduple(self):
        print("sql判例数据去重任务启动")
        for sql in SqlcasedatadeduplestatementS:
            try:
                result = Mysqlhelper().delete(sql)
            except Exception as e:
                with open("sqlerro.txt", "a+", encoding="utf-8") as f:
                    f.write(str(datetime.datetime.now()) + ":" + "sql语句执行出错：" + sql + '\n')
                print(e)
        print("sql判例数据去重任务结束")

    def sqldataduple(self):
        print(str(datetime.datetime.now()) + "：开始进行sql数据去重")
        thread_list = []
        thread1 = threading.Thread(target=self.lawdataduple)
        thread2 = threading.Thread(target=self.casedataduple)
        thread_list.append(thread1)
        thread_list.append(thread2)
        for t in thread_list:
            t.setDaemon(True)
            t.start()
        for t in thread_list:
            t.join()
        print(str(datetime.datetime.now()) + "：sql数据去重结束")
        return True

